#!/bin/sh

queuecpu=50
queueio=30

echo $queuecpu
echo $queueio
make clean;
make;

if [ ! -d "task3" ]; then
	mkdir task3
else
	rm -rf task3/*
fi

echo "Web Server"
for rho in 0.05 0.15 0.25 0.35 0.45 0.55 0.65 0.75 0.85 0.95
do
	echo 'Run' $n 'for rho = '$rho
	./queuesimulation $rho $queuecpu $queueio 100000 1 0 >> task3/output_task3
#		sleep 2
done

grep 'Overall average waiting time*' task3/output_task3 | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task3/overall_waiting

grep 'CPU average*' task3/output_task3 | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task3/cpu_waiting

grep 'IO one average*' task3/output_task3 | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task3/io1_waiting

grep 'IO two average*' task3/output_task3 | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task3/io2_waiting

grep 'IO three average*' task3/output_task3 | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task3/io3_waiting

grep 'Overall system CLR*' task3/output_task3 | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task3/overall_clr

grep 'CPU CLR*' task3/output_task3 | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task3/cpu_clr

grep 'IO one CLR*' task3/output_task3 | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task3/io1_clr

grep 'IO two CLR*' task3/output_task3 | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task3/io2_clr

grep 'IO three CLR*' task3/output_task3 | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task3/io3_clr

grep 'Avg CPU visits*' task3/output_task3 | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task3/cpu_visits

grep 'Avg IO one visits*' task3/output_task3 | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task3/io1_visits

grep 'Avg IO two visits*' task3/output_task3 | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task3/io2_visits

grep 'Avg IO three visits*' task3/output_task3 | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task3/io3_visits
